using BlazorAdmin.Models;
using BlazorAdmin.Models.Dto;
using BootstrapBlazor.Components;
using System.ComponentModel;

namespace BlazorAdmin.Web.Shared.Models
{
    /// <summary>
    /// Device 搜索业务模型
    /// </summary>
    public class DeviceSearchModel : DeviceInfo, ITableSearchModel
    {
        [DisplayName("更新人")]
        public string? updater { get; set; }

        [DisplayName("更新时间")]
        public DateTimeRangeValue? updatetime { get; set; }

        public DeviceSearchModel()
        {
            Reset();
        }

        public IEnumerable<IFilterAction> GetSearches()
        {
            var ret = new List<IFilterAction>();

            if (!string.IsNullOrEmpty(guid))
                ret.Add(new SearchFilterAction(nameof(Device.Guid), guid));

            if (!string.IsNullOrEmpty(ip))
                ret.Add(new SearchFilterAction(nameof(Device.IP), ip));

            if (!string.IsNullOrEmpty(asset_no))
                ret.Add(new SearchFilterAction(nameof(Device.AssetNo), asset_no));

            if (!string.IsNullOrEmpty(type))
                ret.Add(new SearchFilterAction(nameof(Device.DeviceType), type));

            if (!string.IsNullOrEmpty(location))
                ret.Add(new SearchFilterAction(nameof(Device.Location), location));

            if (!string.IsNullOrEmpty(backup_path))
                ret.Add(new SearchFilterAction(nameof(Device.BackupDir), backup_path));

            if (!string.IsNullOrEmpty(version))
                ret.Add(new SearchFilterAction(nameof(Device.Version), version));

            if (!string.IsNullOrEmpty(updater))
                ret.Add(new SearchFilterAction(nameof(Device.Updater), updater));

            if (updatetime != null)
            {
                ret.Add(new SearchFilterAction(nameof(Device.UpdateTime), updatetime.Start, FilterAction.GreaterThanOrEqual));
                ret.Add(new SearchFilterAction(nameof(Device.UpdateTime), updatetime.End, FilterAction.LessThanOrEqual));
            }

            return ret;
        }

        public void Reset()
        {
            guid = null;
            ip = null;
            asset_no = null;
            type = null;
            location = null;
            backup_path = null;
            version = null;
            updater = null;
            updatetime = null;
        }
    }
}
